package com.bls.cate.ui.activity.setting;

import android.content.DialogInterface;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bls.blslib.base.BaseActivity;
import com.bls.cate.R;
import com.bls.cate.ui.activity.login.LoginActivity;
import com.bls.cate.ui.activity.person_info.PersonInfoActivity;
import com.bls.cate.ui.activity.root.RootActivity;
import com.bls.cate.ui.widget.MDialog;
import com.bls.cate.ui.widget.TitleView;
import com.bls.cate.utils.AccountUtil;

/**
 * 　　  () 　　　  ()
 * 　　  ( ) 　　　( )
 * 　　  ( ) 　　　( )
 * 　　┏┛┻━━━┛┻┓
 * 　　┃　　　━　　　┃
 * 　　┃　┳┛　┗┳　┃
 * 　　┃　　　┻　　　┃
 * 　　┗━┓　　　┏━┛
 * 　　　　┃　　　┃
 * 　　　　┃　　　┗━━━┓
 * 　　　　┃　　　　　　　┣┓
 * 　　　　┃　　　　　　　┏┛
 * 　　　　┗┓┓┏━┳┓┏┛
 * 　　　　　┃┫┫　┃┫┫
 * 　　　　　┗┻┛　┗┻┛
 * ——————————————————
 * Created by BinglingSu on 2018/1/18.
 */

public class SettingActivity extends BaseActivity implements MDialog.AlertDialogUtilListener {

    private TextView btnUserInfo, btnChangePassword, btnClearMemory, btnFeedBack, btnLogOut;
    private TitleView titleView;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initFvb() {
        titleView = findViewById(R.id.title_view);
        btnUserInfo = findViewById(R.id.btn_user_info);
        btnChangePassword = findViewById(R.id.btn_change_password);
        btnClearMemory = findViewById(R.id.btn_clear_memory);
        btnFeedBack = findViewById(R.id.btn_feedback);
        btnLogOut = findViewById(R.id.btn_log_out);
    }

    @Override
    protected void initTitle() {
        titleView.titleMiddleText.setText("设置");
        titleView.titleLeftIv1.setVisibility(View.VISIBLE);
        titleView.setTitleClickListener(new TitleView.OnTitleClickListener() {
            @Override
            public void onTitleClick(int btnType) {
                finish();
            }
        });
    }

    @Override
    protected void initView() {
        btnLogOut.setText(AccountUtil.isLogin() ? "登出帐户" : "登陆帐户");
    }

    @Override
    protected void initListener() {
        setOnClickListener(btnUserInfo, btnChangePassword, btnClearMemory, btnFeedBack, btnLogOut);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_user_info:
                ActivityUtils.startActivity(PersonInfoActivity.class);
                break;
            case R.id.btn_change_password:
                ToastUtils.showShort(getString(R.string.to_be_continued));
                break;
            case R.id.btn_clear_memory:
                MDialog.showCommonDialog(getActivity(), null, "确定清除应用缓存么？", "确定", "取消", 0, this);
                break;
            case R.id.btn_feedback:
                ToastUtils.showShort(getString(R.string.to_be_continued));
                break;
            case R.id.btn_log_out:
                MDialog.showCommonDialog(getActivity(), "登出", "确定登出？", "确定", "取消", 1, this);
                break;
        }
    }

    @Override
    public void MyAlertDialogListener(DialogInterface dialog, int dialogFlag, MDialog.MDialogBtnEnum btnEnum) {
        if (dialogFlag == 0) {
            if (btnEnum == MDialog.MDialogBtnEnum.CONFIRM)
                ToastUtils.showShort(getString(R.string.to_be_continued));
        } else if (dialogFlag == 1) {
            if (btnEnum == MDialog.MDialogBtnEnum.CONFIRM && AccountUtil.isLogin()) {
                AccountUtil.eraseLoginSp(getApplicationContext());
                ActivityUtils.startActivity(RootActivity.class);
                finish();
            } else if (btnEnum == MDialog.MDialogBtnEnum.CONFIRM && !AccountUtil.isLogin()) {
                ActivityUtils.startActivity(LoginActivity.class);
                finish();
            }
        }
    }
}
